package com.ycp.erp.role.ui.activity;

import android.annotation.SuppressLint;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jakewharton.rxbinding2.view.RxView;
import com.one.common.common.stateview.item.EmptyItem;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.utils.Toaster;
import com.one.common.view.base.IListView;
import com.one.common.view.pagestate.listpage.BaseListActivity;
import com.one.common.view.widget.MyTitleBar;
import com.ycp.erp.R;
import com.ycp.erp.role.model.bean.Role;
import com.ycp.erp.role.presenter.RolePresenter;
import com.ycp.erp.role.ui.binder.RoleManagerBinder;
import com.ycp.erp.view.HintDialog;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

/**
 * Class Des:
 * Created by bjh on 2021/8/25.
 */
@Route(path = RouterPath.ROLE_MANAGER)
public class RoleManagerActivity extends BaseListActivity<RolePresenter> implements IListView {
    @Override
    protected void initPresenter() {
        mPresenter=new RolePresenter(this,getContext());
    }

    @Override
    public void registerDate() {
        RoleManagerBinder roleManagerBinder =new RoleManagerBinder();
        register(Role.class,roleManagerBinder);
    }

    @Override
    public void loadData() {
        mPresenter.getRoles();
    }

    @SuppressLint("CheckResult")
    @Override
    public void initView() {
        super.initView();
        addTopView(R.layout.layout_search);
        addBottomView(R.layout.layout_submit_bottom);
        TextView tvSubmit  = successView.findViewById(R.id.tvSubmit);
        tvSubmit.setText("添加角色");
        //跳转
        RxView.clicks(tvSubmit).throttleFirst(2, TimeUnit.SECONDS).subscribe(o -> {
            HintDialog dialog = HintDialog.getInstance();
            dialog.setInputHint("输入角色名称");
            dialog.setTitle("新增角色");
            dialog.setInputListener(new HintDialog.InputListener() {
                @Override
                public void onCancel() {

                }

                @Override
                public void onConfirm(String data) {
                    Role role1=new Role();
                    role1.setName(data);
                    role1.setRolePhone("15689954995");
                    addData(role1);
                }
            });
            dialog.show(getSupportFragmentManager(),"");
        });
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("角色管理").hideLine();
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter.getRoles();
    }

    @Override
    public boolean onEmpty() {
        addData(new EmptyItem("暂无数据"));
        return true;
    }


    @Override
    public void onErrorClick() {
        super.onErrorClick();
        refresh();
    }
}
